package com.gitee.wsl.common.commonmark


import org.commonmark.internal.inline.InlineContentParser
import org.commonmark.internal.inline.InlineParserState
import org.commonmark.internal.inline.ParsedInline
import org.commonmark.internal.inline.Scanner
import org.commonmark.node.Node
import java.util.regex.Pattern

object CommonmarkExt {

}



fun Scanner.lineMatch(pattern: Pattern):String?{
    val startPosition = position()
    val mathString = currentLineMatch(pattern)
    mathString?.let {
        setPosition(startPosition)
        next(it)
    }
    return mathString
}

private fun Scanner.currentLineMatch(pattern: Pattern):String?{
    val lineString = StringBuilder()
    var ch:Char
    while(hasNext()){
        ch=peek()
        if(ch !='\n') lineString.append(ch) else break
        next()
    }
    val matcher=pattern.matcher(lineString)
    if(matcher.find()){
        return matcher.group()
    }

    return null
}